/*
 * Copyright (C) 2021 Huawei Device Co., Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.shashank.sony.fancytoastlib.demo.slice;

import com.shashank.sony.fancytoastlib.FancyToast;
import com.shashank.sony.fancytoastlib.demo.ResourceTable;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Button;
import ohos.agp.components.Component;

public class MainAbilitySlice extends AbilitySlice implements Component.ClickedListener {

    Button b1, b2, b3, b4, b5, b6, b7, b8, b9;
    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_main);
        b1 = (Button) findComponentById(ResourceTable.Id_button);
        b2 = (Button) findComponentById(ResourceTable.Id_button2);
        b3 = (Button) findComponentById(ResourceTable.Id_button3);
        b4 = (Button) findComponentById(ResourceTable.Id_button4);
        b5 = (Button) findComponentById(ResourceTable.Id_button5);
        b6 = (Button) findComponentById(ResourceTable.Id_button6);
        b7 = (Button) findComponentById(ResourceTable.Id_button7);
        b8 = (Button) findComponentById(ResourceTable.Id_button8);
        b9 = (Button) findComponentById(ResourceTable.Id_button9);
        b1.setClickedListener(this);
        b2.setClickedListener(this);
        b3.setClickedListener(this);
        b4.setClickedListener(this);
        b5.setClickedListener(this);
        b6.setClickedListener(this);
        b7.setClickedListener(this);
        b8.setClickedListener(this);
        b9.setClickedListener(this);
    }

    @Override
    public void onClick(Component v) {
        if (v.getId() == ResourceTable.Id_button)
            FancyToast.makeText(this, "This is Default Toast", 3000, FancyToast.DEFAULT, false).show();
        else if (v.getId() == ResourceTable.Id_button2)
            FancyToast.makeText(this, "Success Toast !", 3000, FancyToast.SUCCESS, false).show();
        else if (v.getId() ==ResourceTable.Id_button3)
            FancyToast.makeText(this, "This is an Error Toast", 3000, FancyToast.ERROR, false).show();
        else if (v.getId() == ResourceTable.Id_button4)
            FancyToast.makeText(this, "Beware of dog", 3000, FancyToast.WARNING, false).show();
        else if (v.getId() == ResourceTable.Id_button5)
            FancyToast.makeText(this, "Here is some Info for you", 3000, FancyToast.INFO, false).show();
        else if (v.getId() == ResourceTable.Id_button6)
            FancyToast.makeText(this, "This is Confusing Toast", 3000, FancyToast.CONFUSING, false).show();
        else if (v.getId() == ResourceTable.Id_button7)
            FancyToast.makeText(this, "This is Custom Toast", 3000, FancyToast.CONFUSING, ResourceTable.Graphic_ic_ohos_black_24dp, false).show();
        else if (v.getId() == ResourceTable.Id_button8)
            FancyToast.makeText(this, "This is Custom Toast with no icon", 3000, FancyToast.CONFUSING, ResourceTable.Graphic_ic_ohos_black_24dp, false).show();
        else if (v.getId() == ResourceTable.Id_button9)
            FancyToast.makeText(this, "This is a Success Toast", 3000, FancyToast.SUCCESS, false).show();
    }
}
